home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
layertes.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
6KB
|
171 lines
/* layer test program v1.0 */
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
#include <exec/types.h>
#include <graphics/gfx.h>
#include <hardware/dmabits.h>
#include <hardware/custom.h>
#include <graphics/gfxmacros.h>
#include <graphics/rastport.h>
#include <graphics/view.h>
#include <exec/exec.h>
/* ********************** added for layers support ************************ */
#include <graphics/layers.h>
#include <graphics/clip.h>
#define DEPTH 2
#define WIDTH 320
#define HEIGHT 200
#define NOT_ENOUGH_MEMORY -1000
#define FOREVER for(;;)
/* construct a simple display */
#define FLAGS LAYERSMART
struct View v;
struct ViewPort vp;
struct ColorMap *cm; /* pointer to colormap structure, dynamic alloc */
struct RasInfo ri;
struct BitMap b;
/* made 3 separate rastports for layers testing ********************** */
struct RastPort *rp[3]; /* rastport for each layer */
/* dynamically created RastPorts from the calls to CreateUpfrontLayer */
short i,j,k,n;
struct ColorMap *GetColorMap();
struct GfxBase *GfxBase;
SHORT boxoffsets[] = { 802, 2010, 3218 };
USHORT colortable[] = { 0x000, 0xf00, 0x0f0, 0x00f };
/* black, red, green, blue */
UBYTE *displaymem;
UWORD *colorpalette;
struct LayersBase *LayersBase;
struct Layer_Info li;
struct Layer *layer[3];
extern struct Layer *CreateUpfrontLayer();
main()
{
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
if (GfxBase == NULL) exit(1);
LayersBase = (struct LayersBase *)OpenLibrary("layers.library",0);
if(LayersBase == NULL) exit(2);
InitLayers(&li);
/* initialize view */
InitView(&v);
/* link view into viewport */
v.ViewPort = &vp;
/* init view port */
InitVPort(&vp);
/* now specify critical characteristics */
vp.DWidth = WIDTH;
vp.DHeight = HEIGHT;
vp.RasInfo = &ri;
/* init bit map (for rasinfo and rastport) */
InitBitMap(&b,DEPTH,WIDTH,HEIGHT);
/* (init RasInfo) */
ri.BitMap = &b;
ri.RxOffset = 0; /* align upper left corners of display
* with upper left corner of drawing area */
ri.RyOffset = 0;
ri.Next = NULL;
/* (init color table) */
cm = GetColorMap(4); /* 4 entries, since only 2 planes deep */
colorpalette = cm->ColorTable;
for(i=0; i<4; i++)
*colorpalette++ = colortable[i];
/* copy my colors into this data structure */
vp.ColorMap = cm; /* link it with the viewport */
/* allocate space for bitmap */
for(i=0; i<DEPTH; i++)
{
b.Planes[i] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
if(b.Planes[i] == NULL) exit(NOT_ENOUGH_MEMORY);
}
MakeVPort( &v, &vp ); /* construct copper instr (prelim) list */
MrgCop( &v ); /* merge prelim lists together into a real
* copper list in the view structure. */
for(i=0; i<2; i++)
{
displaymem = (UBYTE *)b.Planes[i];
for(j=0; j<RASSIZE(WIDTH,HEIGHT); j++)
*displaymem++ = 0;
/* zeros to all bytes of the display area */ }
LoadView(&v);
/* now fill some boxes so that user can see something */
/* always draw into both planes to assure true colors */
layer[0] = CreateUpfrontLayer(&li,&b,20,20,100,80,FLAGS,NULL);
/* layerinfo, common bitmap, x,y,x2,y2,
* flags = 0 (simple refresh), null pointer to superbitmap */
layer[1] = CreateUpfrontLayer(&li,&b,30,30,110,90,FLAGS,NULL);
layer[2] = CreateUpfrontLayer(&li,&b,40,40,120,100,FLAGS,NULL);
if(layer[0]==NULL || layer[1]==NULL || layer[2]==NULL) exit(3);
rp[0] = layer[0]->rp;
rp[1] = layer[1]->rp;
rp[2] = layer[2]->rp;
SetAPen(rp[0],1);
SetDrMd(rp[0],JAM1);
RectFill(rp[0],0,0,160,100);
SetAPen(rp[1],2);
SetDrMd(rp[1],JAM1);
RectFill(rp[1],0,0,160,100);
SetAPen(rp[2],3);
SetDrMd(rp[2],JAM1);
RectFill(rp[2],0,0,160,100);
FOREVER
moveit();
; /* do nothing till user resets machine */
FreeMemory(); /* discussion purposes only, user has no
* way here to get past "FOREVER" in this
* simple program. FreeMemory is discussed
* in section below... Exiting Gracefully */
} /* end of main() */
FreeMemory()
{ /* return user and system-allocated memory to sys manager */
for(i=0; i<DEPTH; i++) /* free the drawing area */
FreeRaster(b.Planes[i],WIDTH,HEIGHT);
FreeColorMap(cm); /* free the color map */
/* free dynamically created structures */
FreeVPortCopLists(&vp);
FreeCprList(&v.LOFCprList);
return;
}